#include "head.h"

void print_process_arg_list ( pid_t pid )
{
	int fd;
	char filename[24];
	char arg_list[1024];
	size_t length;
	char * next_arg;
	int i = 0;
	int tmpLen = 0;

	snprintf ( filename, sizeof (filename), "/proc/%d/cmdline", (int)pid);
	fd = open (filename, O_RDONLY);
	length = read (fd, arg_list, sizeof(arg_list));
	printf("pid=%d, filename=%s, length=%d\n", pid, filename, length);
	close(fd);
	arg_list[length] ='\0';

	printf("-------------------------------------\n");
	tmpLen = length;
	while(tmpLen--)
	{
		printf("%c", arg_list[i++]);
	}
	printf("\n-------------------------------------\n");

	fflush(stdout); //is necessary, since infinite loop exists after this statement.

	//Loop over arguments. Arguments are seperated by NULs. 
	next_arg = arg_list;

	while(next_arg < arg_list + length )
	{
		printf("%s\n", next_arg);
		next_arg += strlen (next_arg) + 1;
	}

}

	
